﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class updateUsersInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["flag"] == null&&Session["UserName"]==null)
        {
            Response.Write("<script>window.open('../../Login.aspx')</script>");
        }
        if (!IsPostBack)
        {
            
            this.bind();
        }
    }
    public void bind()
    {
        DataSet ds1 = DB.reDs("Select UserName from tb_UserInfo");
        ddlUserName.DataSource = ds1;
        ddlUserName.DataTextField = "UserName";
        ddlUserName.DataBind();
    }
    protected void btnClickOK_Click(object sender, EventArgs e)
    {
        string UserName = this.ddlUserName.SelectedItem.ToString ();
        string OldPassWord=this.txtOldPassword.Text.Trim();
        string NewPassWord = this.txtNewPassword.Text.Trim();
        SqlDataReader sdr = DB.reDr("select * from tb_UserInfo where UserName='" + UserName + "'and Password='"+OldPassWord+"'");
        sdr.Read();
        if (sdr.HasRows)
        {
            DB.ExSql("update tb_UserInfo set Password='" + NewPassWord + "'where UserName='" + UserName + "'");
            Response.Write("<script>alert('修改成功！');location='UpdateUsersInfo.aspx'</script>");
        }
        else
        {
            Response.Write("<script>alert('修改失败！');location='updateUsersInfo.aspx'</script>");
        }
        sdr.Close();
    }
}
